package cn.tsmchina.one.dao.recommendation;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.tsmchina.one.dao.BaseDaoSupport;
import cn.tsmchina.one.domain.recommendation.Recommend;
import cn.tsmchina.one.util.C;

@Repository
public class RecommentDaoImpl extends BaseDaoSupport<Recommend> implements RecommentDao
{
	@Override
	public int addRec(Recommend rec)
	{
		System.out.println("------------------------------");
		System.out.println("------------------------------id=="+rec.getId());
		System.out.println("------------------------------mages=="+rec.getImages());
		System.out.println("------------------------------RecContent=="+rec.getRecContent());
		System.out.println("------------------------------RecName=="+rec.getRecName());
		System.out.println("------------------------------etSummary=="+rec.getSummary());
		System.out.println("------------------------------etCreateDate=="+rec.getCreateDate());
		return (Integer) super.add(rec);
		//System.out.println("--------------77----------------");
	}
	
	@Override
	public void deleteById(int id) {
		super.delete(id);
	}
	
	@Override
	public List<Recommend> recs(int page, long cid)
	{
		String hql = "from Recommend  order by id desc";
		return lists(hql,page,C.Paging.SIZE);
		//return lists(page,C.Paging.SIZE);
	}

	@Override
	public int cancelRec(int id)
	{
		String hql = "update from Recommend a set a.delflag = ? where id = ?";
		return executeUpdate(hql, true,id);
	}

	@Override
	public void updateRec(Recommend rec)
	{
		super.update(rec);
	}

	@Override
	public int total(long cid)
	{
		String hql = "select count(*) from Recommend a where a.customerId=? and a.delflag = 0";
		return count(hql, cid);
	}

	@Override
	public int check(String name, Object value)
	{
		String hql = "select count(*) from Recommend a a."+name+" = ?";
		return executeUpdate(hql, value);
	}

	@Override
	public Recommend findRec(int id)
	{
		return findById(id);
	}

	@Override
	public Recommend getRec(int id)
	{
		return super.findById(id);
	}

	@Override
	public List<Recommend> getRecNotice()
	{
		// TODO Auto-generated method stub
		String hql ="from Recommend a where a.startDate > date(now()) and a.delflag = 0 order by a.createDate desc ";
		return super.lists(hql);
	}

	@Override
	public List<Recommend> getRecShare()
	{
		String hql = "from Recommend a where a.endDate < date(now()) and a.delflag = 0 order by a.createDate desc";
		return super.lists(hql);
	}

	@Override
	public void addJoin(String json,int id)
	{
		String hql = "update from Recommend a set a.joinUserId = ? where a.id = ?";
		super.executeUpdate(hql, json,id);
	}

	@Override
	public void addPraise(String parseJson, int activityId)
	{
		String hql = "update from Recommend a set a.praiseUserId = ? where a.id = ?";
		executeUpdate(hql, parseJson,activityId);
	}

	@Override
	public int redoRec(int id) {
		String hql = "update from Recommend a set a.delflag = ? where id = ?";
		return executeUpdate(hql,false,id);
	}

	@Override
	public int getTotal() {
		// TODO Auto-generated method stub
		String hql = "select count(*) from Recommend o where 1=1";
		return count(hql);
	}
	
}
